package com.jt.demo.controller;

import com.jt.demo.pojo.User;
import com.jt.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 张琪
 * @date 2020/11/26
 * @describe
 */

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public String doFindAll(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("userList", userList);
        return "userList";
    }

    @RequestMapping("doAjax")
    public String doAjax(){
        return "ajax";
    }


    @ResponseBody       // 1. 将返回值转为JSON数据返回,   2. 代表ajax请求结束
    @RequestMapping("/findAllUsers")
    public List<User> doFindUsers(){
        return userService.findAll();
    }
}
